package com.od.controller;


import com.od.entity.Enterprise;
import com.od.service.EnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("enterprise")
@CrossOrigin
public class EnterpriseController {

    @Autowired
    private EnterpriseService enterpriseService;

    /**
     * 根据企业编号查询企业信息，在企业个人界面和筛选会使用
     * @param enterpriseId
     * @return
     */
    @RequestMapping("getEnterpriseById")
    @ResponseBody
    public Enterprise getEnterpriseById(Integer enterpriseId) {
        return enterpriseService.getEnterpriseById(enterpriseId);
    }

    /**
     * 更新企业的个人信息，会在企业管理界面信息会使用
     * @param
     * @return
     */
    @PostMapping("updateEnterpriseById")
    @ResponseBody
    public String updateEnterpriseById(@RequestBody Map<String, Object>  enterpriseData) {
        Enterprise enterprise = new Enterprise();
        enterprise.setEnterpriseId(Integer.parseInt(enterpriseData.get("enterpriseId").toString()));
        enterprise.setTel(enterpriseData.get("tel").toString());
        enterprise.setPassword(enterpriseData.get("password").toString());
        enterprise.setEnterpriseName(enterpriseData.get("enterpriseName").toString());
        enterprise.setEnterpriseProfile(enterpriseData.get("enterpriseProfile").toString());
        enterprise.setEnterpriseScale(Integer.parseInt(enterpriseData.get("enterpriseScale").toString()));
        enterprise.setEnterpriseNature(enterpriseData.get("enterpriseNature").toString());
        enterprise.setEnterpriseCity(Integer.parseInt(enterpriseData.get("enterpriseCity").toString()));
        enterprise.setEnterpriseLocation(enterpriseData.get("enterpriseLocation").toString());
        return enterpriseService.updateEnterpriseInfo(enterprise)>0?"修改企业信息成功":"修改企业失败";
    }

    @RequestMapping("getEnterpriseIdByTel")
    @ResponseBody
    public Integer getEnterpriseIdByTel(String tel) {
        return enterpriseService.getEnterpriseIdByTel(tel);
    }

    @PostMapping("addEnterprise")
    @ResponseBody
    public int addEnterprise(@RequestBody Enterprise enterprise) {//注册企业
        return enterpriseService.addEnterprise(enterprise);
    }


}
